package com.usian.behavior.controller.v1;

import com.usian.behavior.entity.ApLikesBehavior;
import com.usian.behavior.entity.ApUnlikesBehavior;
import com.usian.behavior.service.IApLikesBehaviorService;
import com.usian.behavior.service.IApUnlikesBehaviorService;
import com.usian.model.behavior.dtos.LikesBehaviorDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 查询行为内容
 * @author
 */
@RestController
@RequestMapping("/api/v1/behavior")
public class ApBehaviorController {

    @Autowired
    private IApLikesBehaviorService apLikesBehaviorService;

    @Autowired
    private IApUnlikesBehaviorService apUnlikesBehaviorService;


    /**
     * 根据用户id 设备号 文章id查询 点赞行为、不喜欢行为
     * @param userId
     * @param equipmentId
     * @param articleId
     * @param likeType
     * @return
     */
    @GetMapping("/findBehavior")
    public Map<String,Boolean> findBehavior(@RequestParam(name = "userId") Integer userId,
                                            @RequestParam(name = "equipmentId") String equipmentId,
                                            @RequestParam(name = "articleId") Long articleId,
                                            @RequestParam(name = "type") Integer likeType){
//查询用户点赞和不喜欢行为
        Map<String,Boolean> map = new HashMap<>();
        ApLikesBehavior likesBehavior = apLikesBehaviorService.findLikeByArticleId(userId, equipmentId, articleId, likeType);

//       查询不喜欢行为
        ApUnlikesBehavior unlikesBehavior = apUnlikesBehaviorService.findUnLikeByArticleId(userId, equipmentId, articleId);
        boolean islike=false;
        boolean isunlike=false;

        if (likesBehavior != null && likesBehavior.getOperation()==1) {
           islike=true;
        }

        if (unlikesBehavior != null&&unlikesBehavior.getType()==1) {
          isunlike=true;
        }
        map.put("islike",islike);
        map.put("isunlike",isunlike);
        return map;
    }

}
